takker-sprint template
追加option
code:makeSprint.js
import {weekNumber} from '/api/code/takker/javascriptで日付から月ごとの週数を取得する/weekNumber.js';
import {pageExists} from '/api/code/takker/scrapboxに特定のページが存在するかどうか確かめる/pageExists.js';
import {zero, toYYYYMMDD, openNewPage} from '/api/code/takker/Scrapbox_template_utilities/utilities.js';
// URLだけほしいときに使う
export function makeSprintURL() {
const today = toYYYYMMDD(new Date());
const title = takker-sprint@${year}-${zero(month)}-week${week};
return {project: scrapbox.Project.name, title: title};
}
export async function makeSprintURLWithBody(appendlines = []) {
const {project, title} = makeSprintURL();
const e = array => encodeURIComponent(array.join('\n'));
// 既に作成されている場合はそのページを開く
const isExist = await pageExists(project, title);
if (isExist) {
if (appendlines.length !== 0) {
return https://scrapbox.io/${project}/${title}?body=${e(appendlines)};
}
return https://scrapbox.io/${project}/${title};
}
let aWeekAgo = new Date();
aWeekAgo.setDate(aWeekAgo.getDate() - 7);
const prevWeekData = weekNumber(aWeekAgo);
const today = toYYYYMMDD(new Date());
const prevTitle = takker-sprint@${prevWeekData[0]}-${zero(prevWeekData[1])}-week${prevWeekData[2]};
const lines = [
'やるべき',
...appendlines,
' ',
...Array(31).map(_ => ''),
'/icons/hr.icon',
'やりたい',
' ',
'',
'',
'きになる',
' ',
'',
'',
'前回',
[${prevTitle}],
#${today}];
return https://scrapbox.io/${project}/${title}?body=${e(lines)};
}
export async function makeSprint(appendlines = []) {
return window.open(await makeSprintURLWithBody(appendlines));
}